# 智能客服系统主入口
# 基于阿里 LangChain

from langchain_community.llms import Tongyi
from langchain.chains import ConversationChain
from langchain.memory import ConversationBufferMemory

# 初始化通义千问 LLM
llm = Tongyi(api_key="sk-ad1a94263d4b41d89e34af8bd04f5fad")

# 创建对话记忆
memory = ConversationBufferMemory()

# 构建对话链
conversation = ConversationChain(
    llm=llm,
    memory=memory,
)

def chat_with_customer(user_input):
    response = conversation.run(user_input)
    return response

if __name__ == "__main__":
    print("欢迎使用智能客服系统！输入 'exit' 退出。")
    while True:
        user_input = input("用户: ")
        if user_input.lower() == "exit":
            print("感谢使用，再见！")
            break
        reply = chat_with_customer(user_input)
        print("客服: ", reply)
